<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UC-INT-002：权限管理原型</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/antd@5.12.8/dist/reset.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background-color: #f5f5f5;
            color: #333;
        }
        
        .header {
            background: #fff;
            padding: 16px 24px;
            border-bottom: 1px solid #e8e8e8;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        .breadcrumb {
            color: #666;
            font-size: 14px;
        }
        
        .breadcrumb a {
            color: #1890ff;
            text-decoration: none;
        }
        
        .main-content {
            padding: 24px;
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .toolbar {
            background: #fff;
            padding: 16px 20px;
            border-radius: 8px;
            margin-bottom: 16px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .toolbar-left {
            display: flex;
            gap: 12px;
            align-items: center;
        }
        
        .toolbar-right {
            display: flex;
            gap: 12px;
            align-items: center;
        }
        
        .btn {
            padding: 8px 16px;
            border: 1px solid;
            border-radius: 6px;
            font-size: 14px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: all 0.3s;
        }
        
        .btn-primary {
            background: #1890ff;
            border-color: #1890ff;
            color: #fff;
        }
        
        .btn-primary:hover {
            background: #40a9ff;
            border-color: #40a9ff;
        }
        
        .btn-success {
            background: #52c41a;
            border-color: #52c41a;
            color: #fff;
        }
        
        .btn-success:hover {
            background: #73d13d;
            border-color: #73d13d;
        }
        
        .btn-default {
            background: #fff;
            border-color: #d9d9d9;
            color: #333;
        }
        
        .btn-default:hover {
            border-color: #1890ff;
            color: #1890ff;
        }
        
        .btn-danger {
            background: #fff;
            border-color: #ff4d4f;
            color: #ff4d4f;
        }
        
        .btn-danger:hover {
            background: #ff4d4f;
            color: #fff;
        }
        
        .content-area {
            display: grid;
            grid-template-columns: 300px 1fr;
            gap: 16px;
        }
        
        .sidebar {
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .sidebar-header {
            background: #fafafa;
            padding: 16px 20px;
            border-bottom: 1px solid #e8e8e8;
        }
        
        .sidebar-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
        }
        
        .sidebar-content {
            padding: 16px;
        }
        
        .role-list {
            list-style: none;
        }
        
        .role-item {
            padding: 12px 16px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s;
            margin-bottom: 4px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .role-item:hover {
            background: #f8f9fa;
        }
        
        .role-item.active {
            background: #e6f7ff;
            color: #1890ff;
        }
        
        .role-icon {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
            color: #fff;
        }
        
        .role-icon.admin {
            background: #ff4d4f;
        }
        
        .role-icon.instructor {
            background: #1890ff;
        }
        
        .role-icon.leader {
            background: #52c41a;
        }
        
        .role-icon.student {
            background: #faad14;
        }
        
        .role-info {
            flex: 1;
        }
        
        .role-name {
            font-size: 14px;
            font-weight: 500;
            margin-bottom: 2px;
        }
        
        .role-desc {
            font-size: 12px;
            color: #666;
        }
        
        .role-count {
            font-size: 11px;
            color: #999;
        }
        
        .main-panel {
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .panel-header {
            background: #fafafa;
            padding: 16px 20px;
            border-bottom: 1px solid #e8e8e8;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .panel-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
        }
        
        .panel-actions {
            display: flex;
            gap: 8px;
        }
        
        .panel-content {
            padding: 20px;
        }
        
        .permission-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 16px;
            margin-bottom: 24px;
        }
        
        .permission-group {
            border: 1px solid #e8e8e8;
            border-radius: 8px;
            overflow: hidden;
        }
        
        .permission-header {
            background: #f8f9fa;
            padding: 12px 16px;
            border-bottom: 1px solid #e8e8e8;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .permission-icon {
            font-size: 16px;
        }
        
        .permission-title {
            font-size: 14px;
            font-weight: 500;
            color: #333;
        }
        
        .permission-content {
            padding: 16px;
        }
        
        .permission-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 0;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .permission-item:last-child {
            border-bottom: none;
        }
        
        .permission-name {
            font-size: 13px;
            color: #333;
        }
        
        .permission-desc {
            font-size: 11px;
            color: #666;
            margin-top: 2px;
        }
        
        .permission-switch {
            position: relative;
            width: 40px;
            height: 20px;
            background: #d9d9d9;
            border-radius: 10px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        
        .permission-switch.active {
            background: #1890ff;
        }
        
        .permission-switch::after {
            content: '';
            position: absolute;
            top: 2px;
            left: 2px;
            width: 16px;
            height: 16px;
            background: #fff;
            border-radius: 50%;
            transition: transform 0.3s;
        }
        
        .permission-switch.active::after {
            transform: translateX(20px);
        }
        
        .user-list {
            margin-top: 24px;
        }
        
        .user-list-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }
        
        .user-list-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
        }
        
        .user-search {
            display: flex;
            gap: 8px;
            align-items: center;
        }
        
        .search-input {
            padding: 6px 12px;
            border: 1px solid #d9d9d9;
            border-radius: 4px;
            font-size: 12px;
        }
        
        .user-table {
            width: 100%;
            border-collapse: collapse;
        }
        
        .user-table th,
        .user-table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .user-table th {
            background: #fafafa;
            font-weight: 600;
            color: #333;
            font-size: 12px;
        }
        
        .user-table td {
            font-size: 13px;
        }
        
        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: #1890ff;
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            font-weight: 500;
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .user-name {
            font-weight: 500;
            color: #333;
        }
        
        .user-email {
            font-size: 11px;
            color: #666;
        }
        
        .role-tag {
            padding: 2px 8px;
            border-radius: 4px;
            font-size: 11px;
            font-weight: 500;
        }
        
        .role-tag.admin {
            background: #fff2f0;
            color: #ff4d4f;
        }
        
        .role-tag.instructor {
            background: #e6f7ff;
            color: #1890ff;
        }
        
        .role-tag.leader {
            background: #f6ffed;
            color: #52c41a;
        }
        
        .role-tag.student {
            background: #fffbe6;
            color: #faad14;
        }
        
        .status-tag {
            padding: 2px 8px;
            border-radius: 4px;
            font-size: 11px;
            font-weight: 500;
        }
        
        .status-tag.active {
            background: #f6ffed;
            color: #52c41a;
        }
        
        .status-tag.inactive {
            background: #f5f5f5;
            color: #8c8c8c;
        }
        
        .action-buttons {
            display: flex;
            gap: 4px;
        }
        
        .action-btn {
            padding: 4px 8px;
            border: 1px solid #d9d9d9;
            background: #fff;
            border-radius: 3px;
            font-size: 11px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .action-btn:hover {
            border-color: #1890ff;
            color: #1890ff;
        }
        
        .action-btn.danger:hover {
            border-color: #ff4d4f;
            color: #ff4d4f;
        }
        
        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        
        .modal-content {
            background: #fff;
            border-radius: 8px;
            padding: 24px;
            max-width: 600px;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
        }
        
        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .modal-title {
            font-size: 18px;
            font-weight: 600;
            color: #333;
        }
        
        .modal-close {
            background: none;
            border: none;
            font-size: 20px;
            cursor: pointer;
            color: #999;
        }
        
        .form-item {
            margin-bottom: 16px;
        }
        
        .form-item label {
            display: block;
            font-size: 14px;
            color: #333;
            margin-bottom: 4px;
            font-weight: 500;
        }
        
        .form-item input,
        .form-item select,
        .form-item textarea {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #d9d9d9;
            border-radius: 6px;
            font-size: 14px;
        }
        
        .form-item input:focus,
        .form-item select:focus,
        .form-item textarea:focus {
            outline: none;
            border-color: #1890ff;
            box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
        }
        
        .form-row {
            display: flex;
            gap: 16px;
        }
        
        .form-row .form-item {
            flex: 1;
        }
        
        .modal-footer {
            display: flex;
            justify-content: flex-end;
            gap: 12px;
            margin-top: 20px;
        }
        
        .btn-large {
            padding: 10px 20px;
            font-size: 14px;
        }
        
        @media (max-width: 768px) {
            .content-area {
                grid-template-columns: 1fr;
            }
            
            .sidebar {
                order: -1;
            }
            
            .toolbar {
                flex-direction: column;
                gap: 12px;
            }
            
            .toolbar-left,
            .toolbar-right {
                width: 100%;
                justify-content: center;
            }
        }
    </style>
</head>
<body>
    <!-- 页面头部 -->
    <div class="header">
        <div class="breadcrumb">
            <a href="#">首页</a> > <a href="#">系统管理</a> > 权限管理
        </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
        <!-- 工具栏 -->
        <div class="toolbar">
            <div class="toolbar-left">
                <button class="btn btn-primary" onclick="addUser()">➕ 添加用户</button>
                <button class="btn btn-success" onclick="addRole()">👥 添加角色</button>
                <button class="btn btn-default" onclick="importUsers()">📤 导入用户</button>
                <button class="btn btn-default" onclick="exportUsers()">📥 导出用户</button>
            </div>
            <div class="toolbar-right">
                <button class="btn btn-default" onclick="refreshData()">🔄 刷新</button>
                <button class="btn btn-default" onclick="viewLogs()">📋 操作日志</button>
            </div>
        </div>

        <!-- 内容区域 -->
        <div class="content-area">
            <!-- 侧边栏 -->
            <div class="sidebar">
                <div class="sidebar-header">
                    <div class="sidebar-title">角色列表</div>
                </div>
                <div class="sidebar-content">
                    <ul class="role-list">
                        <li class="role-item active" onclick="selectRole(this, 'admin')">
                            <div class="role-icon admin">管</div>
                            <div class="role-info">
                                <div class="role-name">系统管理员</div>
                                <div class="role-desc">拥有所有权限</div>
                                <div class="role-count">3人</div>
                            </div>
                        </li>
                        <li class="role-item" onclick="selectRole(this, 'instructor')">
                            <div class="role-icon instructor">教</div>
                            <div class="role-info">
                                <div class="role-name">培训教官</div>
                                <div class="role-desc">课程管理权限</div>
                                <div class="role-count">12人</div>
                            </div>
                        </li>
                        <li class="role-item" onclick="selectRole(this, 'leader')">
                            <div class="role-icon leader">组</div>
                            <div class="role-info">
                                <div class="role-name">班组长</div>
                                <div class="role-desc">团队管理权限</div>
                                <div class="role-count">8人</div>
                            </div>
                        </li>
                        <li class="role-item" onclick="selectRole(this, 'student')">
                            <div class="role-icon student">学</div>
                            <div class="role-info">
                                <div class="role-name">学员</div>
                                <div class="role-desc">学习权限</div>
                                <div class="role-count">156人</div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- 主面板 -->
            <div class="main-panel">
                <div class="panel-header">
                    <div class="panel-title">权限配置 - 系统管理员</div>
                    <div class="panel-actions">
                        <button class="btn btn-default" onclick="resetPermissions()">重置</button>
                        <button class="btn btn-primary" onclick="savePermissions()">保存</button>
                    </div>
                </div>
                
                <div class="panel-content">
                    <!-- 权限配置 -->
                    <div class="permission-grid">
                        <div class="permission-group">
                            <div class="permission-header">
                                <span class="permission-icon">👥</span>
                                <span class="permission-title">用户管理</span>
                            </div>
                            <div class="permission-content">
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">查看用户</div>
                                        <div class="permission-desc">查看用户列表和详情</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">添加用户</div>
                                        <div class="permission-desc">创建新用户账户</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">编辑用户</div>
                                        <div class="permission-desc">修改用户信息</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">删除用户</div>
                                        <div class="permission-desc">删除用户账户</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                            </div>
                        </div>

                        <div class="permission-group">
                            <div class="permission-header">
                                <span class="permission-icon">🎓</span>
                                <span class="permission-title">课程管理</span>
                            </div>
                            <div class="permission-content">
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">查看课程</div>
                                        <div class="permission-desc">查看课程列表和详情</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">创建课程</div>
                                        <div class="permission-desc">创建新课程</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">编辑课程</div>
                                        <div class="permission-desc">修改课程内容</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">发布课程</div>
                                        <div class="permission-desc">发布课程供学习</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                            </div>
                        </div>

                        <div class="permission-group">
                            <div class="permission-header">
                                <span class="permission-icon">📊</span>
                                <span class="permission-title">数据管理</span>
                            </div>
                            <div class="permission-content">
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">查看数据</div>
                                        <div class="permission-desc">查看各类数据报表</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">导出数据</div>
                                        <div class="permission-desc">导出数据报表</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">删除数据</div>
                                        <div class="permission-desc">删除历史数据</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                            </div>
                        </div>

                        <div class="permission-group">
                            <div class="permission-header">
                                <span class="permission-icon">⚙️</span>
                                <span class="permission-title">系统设置</span>
                            </div>
                            <div class="permission-content">
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">系统配置</div>
                                        <div class="permission-desc">修改系统配置</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">权限管理</div>
                                        <div class="permission-desc">管理用户权限</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                                <div class="permission-item">
                                    <div>
                                        <div class="permission-name">日志查看</div>
                                        <div class="permission-desc">查看系统日志</div>
                                    </div>
                                    <div class="permission-switch active" onclick="togglePermission(this)"></div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 用户列表 -->
                    <div class="user-list">
                        <div class="user-list-header">
                            <div class="user-list-title">用户列表</div>
                            <div class="user-search">
                                <input type="text" class="search-input" placeholder="搜索用户...">
                                <button class="btn btn-default" onclick="searchUsers()">搜索</button>
                            </div>
                        </div>
                        
                        <table class="user-table">
                            <thead>
                                <tr>
                                    <th>用户</th>
                                    <th>角色</th>
                                    <th>状态</th>
                                    <th>最后登录</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        <div class="user-info">
                                            <div class="user-avatar">张</div>
                                            <div>
                                                <div class="user-name">张三</div>
                                                <div class="user-email">zhangsan@example.com</div>
                                            </div>
                                        </div>
                                    </td>
                                    <td><span class="role-tag admin">系统管理员</span></td>
                                    <td><span class="status-tag active">活跃</span></td>
                                    <td>2024-05-15 14:30</td>
                                    <td>
                                        <div class="action-buttons">
                                            <button class="action-btn" onclick="editUser(this)">编辑</button>
                                            <button class="action-btn" onclick="resetPassword(this)">重置密码</button>
                                            <button class="action-btn danger" onclick="deleteUser(this)">删除</button>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="user-info">
                                            <div class="user-avatar">李</div>
                                            <div>
                                                <div class="user-name">李四</div>
                                                <div class="user-email">lisi@example.com</div>
                                            </div>
                                        </div>
                                    </td>
                                    <td><span class="role-tag instructor">培训教官</span></td>
                                    <td><span class="status-tag active">活跃</span></td>
                                    <td>2024-05-15 13:45</td>
                                    <td>
                                        <div class="action-buttons">
                                            <button class="action-btn" onclick="editUser(this)">编辑</button>
                                            <button class="action-btn" onclick="resetPassword(this)">重置密码</button>
                                            <button class="action-btn danger" onclick="deleteUser(this)">删除</button>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="user-info">
                                            <div class="user-avatar">王</div>
                                            <div>
                                                <div class="user-name">王五</div>
                                                <div class="user-email">wangwu@example.com</div>
                                            </div>
                                        </div>
                                    </td>
                                    <td><span class="role-tag leader">班组长</span></td>
                                    <td><span class="status-tag active">活跃</span></td>
                                    <td>2024-05-15 12:20</td>
                                    <td>
                                        <div class="action-buttons">
                                            <button class="action-btn" onclick="editUser(this)">编辑</button>
                                            <button class="action-btn" onclick="resetPassword(this)">重置密码</button>
                                            <button class="action-btn danger" onclick="deleteUser(this)">删除</button>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="user-info">
                                            <div class="user-avatar">赵</div>
                                            <div>
                                                <div class="user-name">赵六</div>
                                                <div class="user-email">zhaoliu@example.com</div>
                                            </div>
                                        </div>
                                    </td>
                                    <td><span class="role-tag student">学员</span></td>
                                    <td><span class="status-tag active">活跃</span></td>
                                    <td>2024-05-15 11:30</td>
                                    <td>
                                        <div class="action-buttons">
                                            <button class="action-btn" onclick="editUser(this)">编辑</button>
                                            <button class="action-btn" onclick="resetPassword(this)">重置密码</button>
                                            <button class="action-btn danger" onclick="deleteUser(this)">删除</button>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 添加用户弹窗 -->
    <div class="modal" id="addUserModal">
        <div class="modal-content">
            <div class="modal-header">
                <h3 class="modal-title">添加用户</h3>
                <button class="modal-close" onclick="closeModal()">&times;</button>
            </div>
            <div class="modal-body">
                <div class="form-row">
                    <div class="form-item">
                        <label>姓名</label>
                        <input type="text" placeholder="请输入姓名">
                    </div>
                    <div class="form-item">
                        <label>邮箱</label>
                        <input type="email" placeholder="请输入邮箱">
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-item">
                        <label>手机号</label>
                        <input type="tel" placeholder="请输入手机号">
                    </div>
                    <div class="form-item">
                        <label>部门</label>
                        <select>
                            <option value="">请选择部门</option>
                            <option value="training">培训部</option>
                            <option value="production">生产部</option>
                            <option value="quality">质量部</option>
                        </select>
                    </div>
                </div>
                <div class="form-item">
                    <label>角色</label>
                    <select>
                        <option value="">请选择角色</option>
                        <option value="admin">系统管理员</option>
                        <option value="instructor">培训教官</option>
                        <option value="leader">班组长</option>
                        <option value="student">学员</option>
                    </select>
                </div>
                <div class="form-item">
                    <label>初始密码</label>
                    <input type="password" placeholder="请输入初始密码">
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" onclick="closeModal()">取消</button>
                <button class="btn btn-primary" onclick="saveUser()">保存</button>
            </div>
        </div>
    </div>

    <script>
        // 全局变量
        let currentRole = 'admin';

        // 角色选择
        function selectRole(element, role) {
            document.querySelectorAll('.role-item').forEach(item => {
                item.classList.remove('active');
            });
            element.classList.add('active');
            currentRole = role;
            
            // 更新面板标题
            const roleNames = {
                'admin': '系统管理员',
                'instructor': '培训教官',
                'leader': '班组长',
                'student': '学员'
            };
            document.querySelector('.panel-title').textContent = `权限配置 - ${roleNames[role]}`;
            
            // 根据角色更新权限
            updatePermissions(role);
        }

        // 更新权限显示
        function updatePermissions(role) {
            const switches = document.querySelectorAll('.permission-switch');
            
            // 根据角色设置权限
            const rolePermissions = {
                'admin': [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
                'instructor': [true, true, true, false, true, true, true, true, true, true, false, false, false, false, false],
                'leader': [true, false, true, false, true, false, false, false, true, false, false, false, false, false, false],
                'student': [false, false, false, false, true, false, false, false, false, false, false, false, false, false, false]
            };
            
            const permissions = rolePermissions[role] || [];
            switches.forEach((switchEl, index) => {
                if (permissions[index]) {
                    switchEl.classList.add('active');
                } else {
                    switchEl.classList.remove('active');
                }
            });
        }

        // 切换权限
        function togglePermission(element) {
            element.classList.toggle('active');
        }

        // 用户管理
        function addUser() {
            document.getElementById('addUserModal').style.display = 'flex';
        }

        function addRole() {
            console.log('添加角色');
        }

        function editUser(element) {
            console.log('编辑用户');
        }

        function resetPassword(element) {
            if (confirm('确定要重置该用户的密码吗？')) {
                console.log('重置密码');
            }
        }

        function deleteUser(element) {
            if (confirm('确定要删除该用户吗？')) {
                console.log('删除用户');
            }
        }

        function searchUsers() {
            console.log('搜索用户');
        }

        function importUsers() {
            console.log('导入用户');
        }

        function exportUsers() {
            console.log('导出用户');
        }

        function refreshData() {
            console.log('刷新数据');
        }

        function viewLogs() {
            console.log('查看操作日志');
        }

        // 权限管理
        function resetPermissions() {
            if (confirm('确定要重置权限配置吗？')) {
                updatePermissions(currentRole);
            }
        }

        function savePermissions() {
            console.log('保存权限配置');
            alert('权限配置已保存');
        }

        function saveUser() {
            closeModal();
            console.log('保存用户');
        }

        // 弹窗控制
        function closeModal() {
            document.querySelectorAll('.modal').forEach(modal => {
                modal.style.display = 'none';
            });
        }

        // 点击弹窗外部关闭
        document.querySelectorAll('.modal').forEach(modal => {
            modal.addEventListener('click', (e) => {
                if (e.target === modal) {
                    closeModal();
                }
            });
        });

        // 初始化
        document.addEventListener('DOMContentLoaded', () => {
            updatePermissions(currentRole);
        });
    </script>
</body>
</html>

